package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class ROUNDUP extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    double d = 1.0D;
    if ((localObject1 instanceof Number) && (localObject2 instanceof Number))
    {
      if (((Number)localObject2).intValue() < 0)
      {
        for (i = 1; i <= -1 * ((Number)localObject2).intValue(); ++i)
          d *= 10.0D;
        if (((Number)localObject1).doubleValue() >= 0.0D)
          return new Double(()(((Number)localObject1).doubleValue() / d + 1.0D) * d);
        return new Double(()(((Number)localObject1).doubleValue() / d - 1.0D) * d);
      }
      if (((Number)localObject2).intValue() == 0)
      {
        if (((Number)localObject1).doubleValue() >= 0.0D)
          return new Long(()(((Number)localObject1).doubleValue() + 1.0D));
        return new Long(()(((Number)localObject1).doubleValue() - 1.0D));
      }
      for (int i = 1; i <= ((Number)localObject2).intValue(); ++i)
        d *= 10.0D;
      if (((Number)localObject1).doubleValue() >= 0.0D)
        return new Double(()(((Number)localObject1).doubleValue() * d + 1.0D) / d);
      return new Double(()(((Number)localObject1).doubleValue() * d - 1.0D) / d);
    }
    return Primitive.ERROR_NAME;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "ROUNDUP(number,num_digits):远离零值，向上（绝对值增大的方向）舍入数字。\nnumber:为需要向上舍入的任意实数。\nnum_digits:舍入后的数字的位数。\n函数 ROUNDUP 和函数 ROUND 功能相似，不同之处在于函数 ROUNDUP 总是向上舍入数字。\n示例:\nROUNDUP(3.2,0) 等于 4\nROUNDUP(76.9,0) 等于 77\nROUNDUP(3.14159, 3) 等于 3.142\nROUNDUP(-3.14159, 1) 等于 -3.2\nROUNDUP(31415.92654, -2) 等于 31,500\n\n";
  }

  public String getEN()
  {
    return "ROUNDUP(number,num_digits): Rounds a number up, away from 0 (zero).\nNumber is any real number that you want rounded up.\nNum_digits is the number of digits to which you want to round number.\n\nROUNDUP behaves like ROUND, except that it always rounds a number up. \n\nExample:\n   ROUNDUP(3.2,0) = 4\n   ROUNDUP(76.9,0) = 77\n   ROUNDUP(3.14159, 3) = 3.142\n   ROUNDUP(-3.14159, 1) = -3.2\n   ROUNDUP(31415.92654, -2) = 31,500\n\n";
  }
}